package com.power.service.impl;

import com.power.dao.LineDao;
import com.power.dao.impl.LineDaoimpl;
import com.power.ov.ResultDataTable;
import com.power.pojo.Line;
import com.power.service.LineService;

import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 李辽
 * Date: 2020/10/07 17:01
 * Description:
 * Version: V1.0
 */
public class LineServiceimpl implements LineService {
    LineDao lineDao = new LineDaoimpl();
    @Override
    public ResultDataTable QueryListLine(int page, int count) throws SQLException {
        return lineDao.QueryListLine(page,count);
    }

    @Override
    public int ModifiesLineStatus(String state_name, int line_id) throws SQLException {
        int newstate = 0;
        if (state_name.equals("启用")){
            newstate = 2;
        }else {
            newstate = 1;
        }
        //更改tower中属于该线路的杆塔状态
        int result = ModifiesTowerStatus(newstate,line_id);
        return lineDao.ModifiesLineStatus(newstate,line_id);
    }
    private int ModifiesTowerStatus(int newstate, int line_id) throws SQLException {
        return lineDao.ModifiesTowerStatus(newstate,line_id);
    }

    @Override
    public int DeletLine(String line_id) throws SQLException {
        return lineDao.DeletLine(line_id);
    }

    @Override
    public int ModifiesLineDate(Line line) throws SQLException {
        if (line.getState_name().equals("启用")){
            line.setLine_stae(1);
        }else {
            line.setLine_stae(2);
        }
        return lineDao.ModifiesLineDate(line);

    }

    @Override
    public int AddLine(Line line) throws SQLException {
        if (line.getState_name().equals("启用")){
            line.setLine_stae(1);
        }else {
            line.setLine_stae(2);
        }
        return lineDao.AddLine(line);
    }

    @Override
    public ResultDataTable SearchLine(String line_number, int line_run, int page, int limit) throws SQLException {
        System.out.println("进入service层,line_run为"+line_run);
        return lineDao.SearchLine(line_number,line_run,page,limit);
    }

    @Override
    public ResultDataTable ShowSelectLine() throws SQLException {
        return lineDao.ShowSelectLine();
    }

    @Override
    public ResultDataTable showUser() throws SQLException {

        return lineDao.showUser();
    }


}
